/* 用户信息 */
import {
  VuexModule,
  Mutation,
  Action,
  getModule,
  Module
} from "vuex-module-decorators";

import store from "@/store/pc";

interface UserInfo {
  userName: string,
  userId: string,
  token: string
}

// state属性声明
interface TestState {
  foo: string
  userInfo: UserInfo
}

/**
 * 标记当前为 module,可以配置的属性:
 *  namespaced:boolean 启/停用 分模块
 *  stateFactory:boolean 状态工厂
 *  dynamic:boolean 动态创建动态模块,即new Vuex.Store({})里面不用注册的.空着就行.
 *  开启 dynamic 之后必须提供下面的属性:
 *    name:string 指定模块名称
 *    store:Vuex.Store 实体 提供初始的 store
 * 
*/
@Module({
  dynamic: true, store, name: "user", namespaced: true
})
class User extends VuexModule implements TestState {
  // state
  public userInfo = {
    userName: '',
    userId: '',
    token: ''
  };
  public foo = 'foo';

  // getter
  get getFoo(): string {
    return this.foo
  }

  @Mutation
  private CHANGE_FOO(foo: string) {
    this.foo = foo
  }

  @Action
  public changeFoo(foo: string) {
    this.CHANGE_FOO(foo);
  }
}

export const UserModule = getModule(User);
